package com.example.spring.demo.mapper;

import com.example.spring.demo.entity.Task;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2024/12/29 14:45
 **/
@Mapper
public interface TaskMapper {
    @Select("""
select * from task where user_id = #{userId} and status = 0;
""")
    List<Task> getUserTaskList(int userId);
    @Insert("""
insert into task (user_id, message_id, status, create_time, update_time) 
values (#{userId}, #{messageId}, #{status}, now(), now());
""")
    int saveTask(Task task);

    @Select("""
select * from task where id = #{taskId};
""")
    Task getTaskById(int taskId);

    @Update("""
<script>
update task 
set status = #{taskStatus}
where id in
<foreach item='id' index='index' collection='sucTaskList' open='(' separator=',' close=')'> 
#{id} 
</foreach>
</script>
""")
    void updateTaskStatus(@Param("sucTaskList") List<Integer> sucTaskList, @Param("taskStatus") int taskStatus);
}
